class Solution:

    def minOperations(self, s1: str, s2: str, x: int) -> int:
        from math import inf
        y, c, d, cd = 0, inf, inf, inf  # j < i + 1 一致；j = i 不一致 ；j < i - 1 不一致
        for p, q in zip(s1, s2):
            yi, ci, di, cdi = inf, inf, inf, inf
            if p == q:
                yi = y
                ci = min(c + 1, d + x)
                di = min(d, c)
                cdi = cd + 1
            else:
                yi = min(c + 1, d + x)
                ci = min(y, cd + x)
                di = min(y, cd + 1)
                cdi = min(d, c)
            y, c, d, cd = yi, ci, di, cdi
        return y if y < inf else -1


s = Solution()
print(s.minOperations(s1 = "10110", s2 = "00011", x = 4))
print(s.minOperations("11001011111", "01111000110", 2))
